package si.yun.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import si.yun.dao.SyUserMapper;
import si.yun.entity.SyUser;
import si.yun.service.SyLoginService;

/**
 * @ClassName: 用户登录实现类
 * @Description: TODO
 * @Author: 柴秋生
 * @Date 2021/7/28 19:27
 */
@Service
public class SyLoginServiceImpl implements SyLoginService {
    @Autowired
    private SyUserMapper syUserMapper;
    @Autowired
    private si.yun.dao.SyLoginRecordMapper SyLoginRecordMapper;
    /**
     * 登陆页面——用户名密码
     * @Author : 柴秋生
     * @Date : 2021/7/30 11:30
     * @Param : [request, account, password]
     * @Return : si.yun.entity.SyUser
     */
    @Override
    @Transactional
    public SyUser selUser(String account, String password, String ip, String cname) {
        SyUser syUser = syUserMapper.selUser(account, password);
        int indirizzo=0;
        if(syUser!=null){
            indirizzo=indirizzo(syUser.getUserId(),ip,cname);
            return syUser;
        }

       // String regione = AddressUtils.indirizzo(ip);//通过将IP传入获取详细位置

        if(syUser==null||indirizzo==0){
            throw new RuntimeException();
        }
        return null;

    }
    /**
     * @Author :柴秋生
     * @Date : 2021/7/30 11:30
     * @Param : [request, id]
     * @Return : int
     */
    @Transactional
    public int indirizzo(int id, String ip, String regione){
        int indirizzo=SyLoginRecordMapper.indirizzo(ip,regione,id);
        return indirizzo;
    }
}
